package com.gitee.jjnnzb.designpatterninspring.business.login.controller;

import com.gitee.jjnnzb.designpatterninspring.business.login.entity.bo.MobileLoginParam;
import com.gitee.jjnnzb.designpatterninspring.business.login.entity.bo.ThirdPartyLoginParam;
import com.gitee.jjnnzb.designpatterninspring.business.login.entity.bo.WebLoginParam;
import com.gitee.jjnnzb.designpatterninspring.business.login.entity.vo.TokenRt;
import com.gitee.jjnnzb.designpatterninspring.business.login.service.LoginDemoService;
import com.gitee.jjnnzb.designpatterninspring.common.bean.ResponseBean;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Jjn
 * @since 2023/8/8 13:53
 */
@RequiredArgsConstructor
@RestController
@Tag(name = "登录接口")
public class LoginDemoController {
    
    private final LoginDemoService loginDemoService;
    
    @PostMapping(value = "/api/v1/demo/login")
    @Operation(description = "普通Web端登录,校验图形验证码,校验机构的可信IP,系统代码", operationId = "Web端登录V1")
    public ResponseBean<TokenRt> webLogin(@RequestBody @Validated WebLoginParam webLoginParam) {
        return ResponseBean.success(loginDemoService.webLogin(webLoginParam));
    }
    
    @PostMapping(value = "/api/v1/demo/third-party/login")
    @Operation(description = "三方登录,仅校验用户名称,系统代码和clientId", operationId = "三方登录V1")
    public ResponseBean<TokenRt> bdLogin(@RequestBody @Validated ThirdPartyLoginParam bdLoginParam) {
        return ResponseBean.success(loginDemoService.thirdPartyLogin(bdLoginParam));
    }
    
    @PostMapping(value = "/api/v1/demo/mobile/login")
    @Operation(description = "手机端登录接口,校验用户名密码", operationId = "手机端登录V1")
    public ResponseBean<TokenRt> mobileLogin(@RequestBody @Validated MobileLoginParam mobileLoginParam) {
        return ResponseBean.success(loginDemoService.mobileLogin(mobileLoginParam));
    }
}
